#include <iostream>
#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>
#include <sstream>

#include "GuiListener.hpp"
#include "Frame.hpp"
#include "Button.hpp"
//#include "LineEdit.hpp"


using namespace std;

int main()
{
    sf::RenderWindow window(sf::VideoMode(800,600,32), "GUI test");
    sf::Event event;

    sf::Clock myClock;
    float myLastTime;

    gui::GuiListener* myListener = gui::GuiListener::GetSingleton();
    gui::Button button("FPS: 0");
        button.SetTextColor(sf::Color(0,0,0));
        button.SetBgColor(sf::Color(125,125,125));
        button.SetBorderColor(sf::Color(0,0,0));
        //button.SetPosition(10,10);

    gui::Frame frame;
        button.SetParent(&frame);
        frame.SetSize(200,200);
        frame.SetPosition(10,10);

  //  gui::LineEdit lineedit;
     //   lineedit.SetPosition(5,60);

    myListener->AddWidget(&frame);
    myListener->AddWidget(&button);
    window.SetFramerateLimit(60);

    while (window.IsOpened())
    {
        while( window.GetEvent(event) || myListener->GetEvent(event) )
        {
            if(event.Type == sf::Event::Closed)
                window.Close();

            else if(myListener->PushEvent(event))
            {
                //cout << "GuiEvent transmitted" << endl;
            }

        }
        if(myClock.GetElapsedTime() > myLastTime+1.f)
        {
            myLastTime = myClock.GetElapsedTime();
            ostringstream fps;
            fps << (int)( 1 / window.GetFrameTime());
            //myFPS.SetString("FPS : " +  fps.str());
            button.SetText("FPS : " + fps.str());
        }

        window.Clear(sf::Color(255,255,255));

        myListener->RenderGui(window);
        window.Display();
    }

    gui::GuiListener::DeleteSingleton();
    return 0;
}
